package com.nycreativity.elecreativity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage
import com.nycreativity.elecreativity.entity.param.sku.SkuQueryParam
import com.nycreativity.elecreativity.entity.po.Sku
import com.nycreativity.elecreativity.entity.vo.goods.SkuOfGoodsVO
import com.nycreativity.elecreativity.entity.vo.sku.SkuVO
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-03-22
 */
interface SkuMapper : BaseMapper<Sku> {

    fun selectPageByCondition(iPage: IPage<Any>, @Param("param") skuQueryParam: SkuQueryParam): IPage<SkuVO>

    fun selectByGoodsIdAndSpecification(
        @Param("goodsId") goodsId: Long,
        @Param("size") size: String?,
        @Param("color") color: String?
    ): List<SkuVO>?

    fun updateSizeByGoodsId(
        @Param("goodsId") goodsId: Long,
        @Param("oldOne") oldOne: String,
        @Param("newOne") newOne: String
    )

    fun updateColorByGoodsId(
        @Param("goodsId") goodsId: Long,
        @Param("oldOne") oldOne: String,
        @Param("newOne") newOne: String
    )

    /**
     * 查询商品对应的规格信息
     * @param goodsId Long 商品id
     * @return GoodsSpecificationDTO 商品对应的规格信息
     */
    @Select("SELECT id as sku_id, specification FROM sku WHERE goods_id = #{goodsId}")
    fun selectGoodsSpecification(goodsId: Long): List<SkuOfGoodsVO>

}
